using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CandyGreat : Sugar
{	
	public UISprite imageSp;
	public UILabel levelLb;
	// Use this for initialization
	void Start ()
	{
		RefreshSugar();	
	}
	
	// Update is called once per frame
	void Update () 
	{
		MoveMySugar();
	}

	/// <summary>
	/// All Sugar have these function
	/// </summary>
	/// 
	public override List<Sugar> GetListMixSugar()
	{
		List<Sugar> listCandyR = new List<Sugar>();
		for (int i = this.col + 1; i < mapLoad.col; i++)
		{
			if (arrSugar[i, this.row] != null)
			{
				if (arrSugar[i, this.row].colorCd == this.colorCd)
				{
					listCandyR.Add(arrSugar[i, this.row]);
				}
				else
				{
					break;
				}
			}
		}

		for (int i = this.col - 1; i >= 0; i--)
		{
			if (arrSugar[i, this.row] != null)
			{
				if (arrSugar[i, this.row].colorCd == this.colorCd)
				{
					listCandyR.Add(arrSugar[i, this.row]);
				}
				else
				{
					break;
				}
			}
		}
		if (listCandyR.Count < DUtil.minCandyMix - 1)
		{
			listCandyR.Clear();
		}
		for (int j = this.row + 1; j < mapLoad.row; j++)
		{
			if (arrSugar[this.col, j] != null)
			{
				if (arrSugar[this.col, j].colorCd == this.colorCd)
				{
					listCandyR.Add(arrSugar[this.col, j]);
				}
				else
				{
					break;
				}
			}
		}

		for (int j = this.row - 1; j >= 0; j--)
		{
			if (arrSugar[this.col, j] != null)
			{
				if (arrSugar[this.col, j].colorCd == this.colorCd)
				{
					listCandyR.Add(arrSugar[this.col, j]);
				}
				else
				{
					break;
				}
			}
		}
		if (listCandyR.Count < DUtil.minCandyMix - 1)
		{
			listCandyR.Clear();
		}
		return listCandyR;
	}

	public override void MixWith(Sugar sugar)
	{
		if (sugar != null && sugar.stt != SugarStatus.Transparent)
		{
			this.level += sugar.level*2;
		}
	}

	public override void RefreshSugar()
	{
		levelLb.text = level.ToString();
		switch (colorCd)
		{
			case ColorSugar.Blue:
				imageSp.spriteName = ImageSugar.Blue;
				break;
			case ColorSugar.Green:
				imageSp.spriteName = ImageSugar.Green;
				break;
			case ColorSugar.Orange:
				imageSp.spriteName = ImageSugar.Orange;
				break;
			case ColorSugar.Purple:
				imageSp.spriteName = ImageSugar.Purple;
				break;
			case ColorSugar.Red:
				imageSp.spriteName = ImageSugar.Red;
				break;
			case ColorSugar.Yellow:
				imageSp.spriteName = ImageSugar.Yellow;
				break;
		}
		Rect sizeSprite = imageSp.atlas.GetSprite(imageSp.spriteName).inner;
		imageSp.transform.localScale = new Vector3(
			sizeSprite.width,
			sizeSprite.height,
			0);
	}

	public override void LogicMinus()
	{
		//GameObject.DestroyImmediate(gameObject);
		imageSp.spriteName = ImageSugar.Empty;
		stt = SugarStatus.Transparent;
		Rect sizeSprite = imageSp.atlas.GetSprite(imageSp.spriteName).inner;
		imageSp.transform.localScale = new Vector3(
			sizeSprite.width,
			sizeSprite.height,
			0);
		MoveToStartPos();
	}

	public override void Logic_Plus()
	{
		LogicMinus();
	}
	/// <summary>
	/// END All Sugar have these function
	/// </summary>
	/// 
}
